package com.vcms.utility.loader;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */

import java.util.*;
import java.io.*;

import com.vcms.exception.VMCSException;

public class PropertyLoader {

	private Properties prop;
	private String fileName;

	public PropertyLoader(String fname) {
		fileName = fname;
	}

	public void initialize() throws VMCSException {
		try {
			prop = new Properties(System.getProperties());
			FileInputStream stream = new FileInputStream(fileName);
			prop.load(stream);
			stream.close();
		} catch (Exception e) {
			throw new VMCSException("PropertyLoader.initialize","Error loading STORE properties: " + e);
		}
	}

	public int getNumOfItems() {
		return Integer.parseInt(prop.getProperty("NumOfItems"));
	}

	public void setNumOfItems(int vl) {
		prop.setProperty("NumOfItems", String.valueOf(vl));
	}

	public String getValue(String key) {
		return prop.getProperty(key);
	}

	public void setValue(String key, String value) {
		prop.setProperty(key, value);
	}

	public void saveProperty() throws VMCSException {
		try {
			FileOutputStream os = new FileOutputStream(fileName);
			prop.store(os, "-----------fileName----------");
			os.close();
		} catch (IOException e) {
			throw new VMCSException("PropertyLoader.save",
					"Error in saving the property file" + e);
		}
	}
}